package com.example.admin.yuejian_22.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.admin.yuejian_22.Fragment.CommentFragment;
import com.example.admin.yuejian_22.Fragment.SendCommentFragment;
import com.example.admin.yuejian_22.Model.UserModel;
import com.example.admin.yuejian_22.R;
import com.squareup.picasso.Picasso;

public class PhotoDetailActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageButton photodetail_back;
    private TextView photodetail_username;
    private TextView photodetail_uupdatetime;
    private TextView photodetail_notice;
    private ImageView photodetail_thum;
    private TextView photodetail_introduction;
    private RadioButton photodetail_comment;
    private RadioButton photodetail_sendcomment;
    private CommentFragment commentFragment;
    private SendCommentFragment sendcommentFragment;
    private FragmentTransaction transaction;
    private FragmentManager fragmentManager;
    private Context Context;
    private String id;
    private String userid;
    private String reply_userid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_detail);
        photodetail_back = (ImageButton) findViewById(R.id.photodetail_back);
        photodetail_username = (TextView) findViewById(R.id.photodetail_username);
        photodetail_uupdatetime = (TextView) findViewById(R.id.photodetail_uupdatetime);
        photodetail_notice = (TextView) findViewById(R.id.photodetail_notice);
        photodetail_thum = (ImageView) findViewById(R.id.photodetail_thum);
        photodetail_introduction = (TextView) findViewById(R.id.photodetail_introduction);
        photodetail_comment = (RadioButton) findViewById(R.id.photodetail_comment);
        photodetail_sendcomment = (RadioButton) findViewById(R.id.photodetail_sendcomment);
        Intent intent = getIntent();
        id = intent.getStringExtra("shaitu_id");
        userid = intent.getStringExtra("userid");
        reply_userid = intent.getStringExtra("reply_userid");

        photodetail_username.setText(intent.getStringExtra("username"));
        photodetail_uupdatetime.setText(intent.getStringExtra("update_time"));
        photodetail_notice.setText(intent.getStringExtra("notice"));
        photodetail_introduction.setText(intent.getStringExtra("introduction"));
        String thum = intent.getStringExtra("thumb");
        String address = "http://172.24.10.175/workout/Uploads/" + thum;
        Picasso.with(Context).load(address).into(photodetail_thum);
        fragmentManager =getSupportFragmentManager();

        photodetail_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        photodetail_comment.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    commentFragment = new CommentFragment();
                    replageFragment(commentFragment);
                }
            }
        });
        photodetail_sendcomment.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sendcommentFragment = new SendCommentFragment();
                    replageFragment(sendcommentFragment);
                }
            }
        });
    }

    private void replageFragment(Fragment fragment) {
        transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_holder_comment, fragment);
        transaction.commit();
    }

    @Override
    public void onClick(View view) {

    }
}
